package com.rentcars.controller;

import com.github.pagehelper.Page;
import com.rentcars.entity.CarSelfuse1;
import com.rentcars.entity.Result;
import com.rentcars.service.Selfuse1Service;
import com.rentcars.utils.DateUtils;
import lombok.Getter;
import lombok.Setter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * 汽车自用
 * @author 浩
 */

@RestController
public class SelfuseController {
    @Autowired
    @Getter
    @Setter
    private Selfuse1Service selfuse1Service;

    @RequestMapping("/selgetPage")
    public Map queryRepair(int pageNum, int pageSize, CarSelfuse1 carSelfuse1) {
        Map map = new HashMap();
        map.put("pageSize", pageSize);
        map.put("pageNum", pageNum);
        map.put("carSelfuse", carSelfuse1);
        Page page = selfuse1Service.qureyUsersByPage(map);
        map.put("page", page);
        map.put("totalPage", page.getPages());
        return map;
    }

    @RequestMapping("/selAdd")
    public Result add(CarSelfuse1 carSelfuse1){
        selfuse1Service.insert(carSelfuse1);
        return new Result();
    }
    @RequestMapping("/selDel")
    public Result getDel(String recordid){
        selfuse1Service.deleteByPrimaryKey(recordid);
        return new Result();
    }
    @RequestMapping("/selGetById")
    public ModelAndView getById(String recordid) throws Exception{
        CarSelfuse1 carSelfuse1 = selfuse1Service.selectByPrimaryKey(recordid);
        Map<String,Object> map=new HashMap<>();
        Date returntime= DateUtils.getDate(carSelfuse1.getReturntime());
        Date usercartime= DateUtils.getDate(carSelfuse1.getUsecartime());
        Date predtime= DateUtils.getDate(carSelfuse1.getPredtime());
        map.put("recorid",recordid);
        map.put("carid", carSelfuse1.getCarid());
        map.put("headman", carSelfuse1.getHeadman());
        map.put("noticeitem", carSelfuse1.getNoticeitem());
        map.put("headmobile", carSelfuse1.getHeadmobile());
        map.put("initmile", carSelfuse1.getInitmile());
        map.put("initoil", carSelfuse1.getInitoil());
        map.put("remark", carSelfuse1.getRemark());
        map.put("returnmile", carSelfuse1.getReturnmile());
        map.put("returnoil", carSelfuse1.getReturnoil());
        map.put("returntime",returntime);
        map.put("usercartime",usercartime);
        map.put("predtime",predtime);
        return new ModelAndView("selfuse-edit",map);
    }
    @RequestMapping("/selEdit")
    public Result getEdit(CarSelfuse1 carSelfuse1){
        selfuse1Service.updateByPrimaryKey(carSelfuse1);
        return new Result();
    }
    //主页面
    @RequestMapping("/selist")
    public ModelAndView getSelf1() {
        return new ModelAndView("selfuse-list");
    }

    @RequestMapping("/selfuse-add")
    public ModelAndView getSelf() {
        return new ModelAndView("selfuse-add");
    }

}
